home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
qsam300.zip
/
QSAM300.DOC
< prev
next >
Wrap
Text File
|
1989-04-05
|
21KB
|
533 lines
A B-Tree Access Method
for QuickBASIC Programmers.
QSAM 3.0 (C)1989 Cornel Huth
Feel free to use QSAM in any program of yours. No registration
or payment is required. If you want the source code send $20.00
to:
Cornel Huth
ATTN: QSAM SOURCE
6402 Ingram Rd.
San Antonio, TX 78238
I will send you the latest version of QSAM source on
5¼" DS/DD IBM-readable diskette. The source includes
the QSAM low-level stuff (written in MASM-compatible
assembly) and the QuickBASIC 4.0 I/O and interface.
-----------------------------------------------------------------
QSAM is a keyed-file system based on the b-tree sorting method.
In addition to finding any particular key and its associated
data record very quickly, QSAM allows sequential access to
the data file (not usually found in b-tree access programs).
This program was originally created by Rick Grehan for Turbo-C.
He has submitted it to the public domain and I thank him for that
and the nice work he did on the very readable assembly code.
What you should find in the QSAM package is the QSAM300.LIB,
QSAM300.DOC, and QSTEST.BAS and QSAM300.BI.
Add QSAM300.LIB to your standard library if you like, and then
LINK /QU it into a QLB library for the environment.
C>lib yourstd.lib +qsam300.lib;
C>link /qu yourstd.lib,qb.qlb,nul,bqlb40.lib
-----------------------------------------------------------------
Interface summary:
All QSAM routines are FUNCTIONs and return an integer code
which is detailed in Error Codes. These must be DECLAREd.
1) Qcreatkf%(filename$,keylen%,kftype$)
2) Qcreatdf%(filename$,reclen%)
3) Qopenk%(filename$,fileno%)
4) Qopend%(filename$,fileno%)
5) Qcreatkr%(kfile%,dfile%,Qkey$,Qrec$)
6) Qreadkr%(kfile%,dfile%,Qkey%,Qrec$)
7) Qreadnkr%(kfile%,dfile%,Qkey$,Qrec$)
8) Qinsertk%(kfile%,dfile%,Qkey$)
9) Qwritedr%(dfile%,Qrec$)
10) Qrewindk%(kfile%)
11) Qdelk%(kfile%,Qkey$)
12) Qdelkr%(kfile%,dfile%,Qkey$)
13) Qclosek%(kfile%)
14) Qclosed%(dfile%)
15) Qfileattrk%(kfile%,keylen%,keys&,bfileno%,kftype$)
16) Qfileattrd%(dfile%,reclen%,recs&,bfileno%,dftype$)
-----------------------------------------------------------------
Interface detail:
1) Qcreatkf(filename$,keylen,kftype$)
Create a new, empty key file. If filename$ exists, its
header will be overwritten by null data.
filename$ - string. Pathname of key file to create.
Any valid DOS drive/path/filename can be used.
keylen - integer. Length of key for this key file.
Valid range is 1 to 64 bytes.
kftype$ - string. For a sorting-only file, kftype$="O".
For an indexing file, kftype$ = "K". "O" is
key-Only and has no associated data file (and
data records). It can be used as a sorting
method. For "K" files, you should create a
data file.
filename$ = "C:\HIST\AR89.KEY"
keylen = 16
kftype$ = "K"
stat = Qcreatkf(filename$,keylen,kftype$)
2) Qcreatdf(filename$,reclen)
Create a new data file. If filename$ exists, its header
will be overwritten by null data.
filename$ - string. Pathname of data file to create.
Any valid DOS drive/path/filename can be used.
reclen - integer. Length of record for this data file.
Valid range is 3 to 32767 bytes.
filename$ = "C:\HIST\AR89.DAT"
reclen = 128
stat = Qcreatdf(filename$,reclen)
3) Qopenk(filename$,fileno)
Open an existing key file and associate it with fileno.
If the file is a key file, a data file will also need
to be opened. You may have multiple index files opened for
a data file. The fileno is an arbitrary number. It does
not reflect either a BASIC handle nor a DOS handle. It is,
however, used to reference the key file in any later operation.
QSAM uses the BASIC FREEFILE function to obtain an
available channel but hides this from the application.
Use Qfileattrk() for information on the key file.
filename$ - string. Pathname of existing key file.
fileno - integer. Number to associate the key file
with for future operations. Valid range is
0 to 9.
filename$ = "C:\HIST\AR89."
ARKEY = 0
ARDAT = 0
stat = Qopenk(filename$+"KEY",ARKEY)
if stat = 0 then
kfile = fileno
stat = Qopend(filename$+"DAT",ARDAT)
4) Qopend(filename$,fileno)
Open an existing data file and associate it with fileno.
The fileno is an arbitrary number. It does not reflect
either a BASIC handle nor a DOS handle. It is, however,
used to reference the data file in any later operation.
Use Qfileattrd() for information on the data file.
filename$ - string. Pathname of existing data file.
fileno - integer. Number to associate the data file
with for future operations. Valid range is
0 to 9.
{see Qopenk() for an example}
5) Qcreatkr(kfile,dfile,Qkey$,Qrec$)
Add the key, Qkey$, to the key file, kfile, and the data
record, Qrec$, to the data file, dfile. Qkey$ must
not already exist. QSAM is case-sensative so it is
recommended that keys be made upper-case (or lower) unless
there is a reason not to do this.
kfile - integer. Number that was used as fileno in
openk().
dfile - integer. Number that was used as fileno in
opend().
Qkey$ - string. Key to add to key file.
Qrec$ - string. Data record to add to the data file
that is indexed by Qkey$.
kfile = 0
dfile = 0
Qkey$ = acctid$ + acctxn$
Qrec$ = xaction$
stat = Qcreatkr(kfile,dfile,Qkey$,Qrec$)
6) Qreadkr(kfile,dfile,Qkey$,Qrec$)
Search for key, Qkey$, in kfile, and if found, retrieve
the data record from dfile, and place it in Qrec$.
kfile - integer. Number that was used as fileno in
openk().
dfile - integer. Number that was used as fileno in
opend().
Qkey$ - string. Key for which to search in key file.
Qrec$ - string. Returned data record associated with
Qkey$.
kfile = 0
dfile = 0
Qkey$ = acctid$ + acctxn$
stat = Qreadkr(kfile,dfile,Qkey$,Qrec$)
7) Qreadnkr(kfile,dfile,Qkey$,Qrec$)
Retrieve the next ordered key in kfile, placing it in Qkey$,
and place its data record from dfile into Qrec$. This
function allows for sequential processing